using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Entitas;
using System;

public sealed class NotifyStatisticsChangeSystem : ReactiveSystem
{
    public NotifyStatisticsChangeSystem(Contexts contexts) : base(contexts.core) {

    }

    protected override Collector GetTrigger(Context context) {
        return context.CreateCollector(CoreMatcher.Statistics, GroupEvent.AddedOrRemoved);
    }

    protected override bool Filter(Entity entity) {

        return true;
    }

    protected override void Execute(List<Entity> entities)
    {
        foreach (var entity in entities)
        {
            if (entity.hasStatisticsListener)
                entity.statisticsListener.listener.StatisticsChanged(entity.statistics);
        }
    }
}
